package com.mammoth.Bodybuilding.service.Impl;

import java.util.List;
import javax.transaction.Transactional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mammoth.Bodybuilding.entity.RegionObj;
import com.mammoth.Bodybuilding.respository.IRegionRepository;
import com.mammoth.Bodybuilding.service.IRegionService;

import net.sf.json.JSONObject;

/**
 * 
 * @title : RegionServiceImpl
 * @description : 区域 服务层实现
 * @company : com.mammoth.Bodybuilding.service.Impl
 * @project Mammoth
 * @author xingzhaojun
 * @date 2018年4月16日 下午4:54:54
 */
@Service
@Transactional
public class RegionServiceImpl implements IRegionService {

	/** 定义一个全局的记录器，通过LoggerFactory获取 **/
	private final static Logger logger = LoggerFactory.getLogger(RegionServiceImpl.class);

	/** 注入用户数据仓库 **/
	@Autowired
	private IRegionRepository regionRespository;

	@Override
	public JSONObject getProvince() {
		JSONObject result = new JSONObject();
		List<RegionObj> regions = regionRespository.findProvince();
		result.put("province", regions);
		logger.info("省份信息查询完毕");
		return result;
	}

	@Override
	public JSONObject getCity(Long provinceId) {
		JSONObject result = new JSONObject();
		List<RegionObj> regions = regionRespository.findCity(provinceId);
		result.put("city", regions);
		logger.info("城市信息查询完毕");
		return result;
	}

	@Override
	public JSONObject getArea(Long cityId) {
		JSONObject result = new JSONObject();
		List<RegionObj> regions = regionRespository.findArea(cityId);
		result.put("area", regions);
		logger.info("城市信息查询完毕");
		return result;
	}

}
